x=int(input())
M=0
x1=x
x2=x//10
x3=x//100
x4=x//1000
x5=x%1000
x6=x%1000//10
x7=x%1000//100
x8=x%100
x9=x%100//10
x10=x%10
S=[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
if 999<x and 10000>x:  
   for y in S:
       k=0
       for i in range(1,y//2+1):
            if y%i==0:
                   k+=1
       if k==1:
            M=max(M,y)
print(M)    
